$('a.menu-item[data-id=home]').addClass('active');

conBanner()

function conBanner() {

    $('.con-video .swiper-wrapper').after('<div class="swiper-pagination"></div>')
    new Swiper('.con-video', {
        autoplay: true, //可选选项，自动滑动
        pagination: {
            el: '.swiper-pagination',
        },
    });

    $('.con-video .con-video-box .icon-close').click(function () {
        $('#homeVideo')[0].pause()
        $('.con-video .con-video-box').removeClass('active')
    })

    for (let i = 0; i < $('.video-play').length; i++) {
        const element = $('.video-play')[i];
        if (!element.dataset.src) {
            $(element).css("display", 'none')
        }
    }

    $('.video-play').click(function () {
        $('#homeVideo')[0].src = this.dataset.src || ''
        $('.con-video .con-video-box').addClass('active')
        setTimeout(() => {
            $('#homeVideo')[0].play()
        }, 367);
    });
}

function conYear() {
    var current = 1
    $('.con-year .arrow-left').click(function () {
        if (current == 1) current = $('.con-year .item').length
        else current--
        addClass()

    })
    $('.con-year .arrow-right').click(function () {
        if (current == $('.con-year .item').length) current = 1
        else current++
        addClass()
    })

    $('.con-year .item').click(function (e) {
        current = getIndex(this.className)
        addClass()
    })

    addClass()

    function addClass() {
        $('.con-year .item').removeClass('active')
        $('.con-year .item' + current).addClass('active')
        $('.year-items').css({
            transform: `translate3d(-${17.1354 * (current >4?current - 4: 0)}vw,0,0)`
        })
    }
}

conYear();

//下面就是滑动的懒加载操作了

var conList_1Num = 0
var conAppNum = 0
// 实际想绑定在 scroll 事件上的 handler
function realFunc(e) {
    var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    var conList_1 = $('.con-new-list1').offset()
    var conApp = $('.con-app').offset()

    // console.log(e.touches[0].clientY)
    if (e && e.touches) {
        scrollTop = e.touches[0].pageY
    }


    if (scrollTop >= conList_1.top - 400 && conList_1Num++ == 0) {
        var len = $('.con-new-list1 img').length
        for (let index = 0; index < len; index++) {
            setTimeout(function () {
                $('.con-new-list1 img')[index].className = 'in'
            }, index * 40)
        }
    }


    if (scrollTop >= conApp.top - 400 && conAppNum++ == 0) {
        var len = $('.con-app .item').length
        for (let index = 0; index < len; index++) {
            setTimeout(function () {
                $('.con-app .item')[index].className += ' in'
            }, index * 40)
        }
    }

}

realFunc()

// 采用了防抖动
// console.log(e.touches[0].clientY)
window.addEventListener('scroll', throttle(realFunc, 10));
window.addEventListener('touchstart', realFunc);